package script.functions

import com.tang.script.functions.ScriptFunction

import java.text.SimpleDateFormat

@ScriptFunction(functionName = "取星期几")
static def getWeek(String str) {
    if (str == null || str == '') return null
    Calendar calendar = Calendar.getInstance()
    Date date = null
    try {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
        date = format.parse(str)
    } catch (Exception e) {}

    try {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd")
        date = format.parse(str)
    } catch (Exception e) {}
    if (date == null) return null

    calendar.setTime(date)
    int week = calendar.get(Calendar.DAY_OF_WEEK) - 1
    String[] number = new String[]{'日', '一', '二', '三', '四', '五', '六'}
    return "星期" + number[week]
}
